﻿package mortal.game.view.common
{
    import com.mui.controls.*;
    import com.mui.utils.*;
    import flash.events.*;
    import mortal.common.swfPlayer.*;
    import mortal.common.swfPlayer.data.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.copy.QuestionCopy.data.*;
    import mortal.game.view.copy.groupCopy.view.*;
    import mortal.mvc.core.*;

    public class ActionBaseIcon extends View
    {
        protected var btn:GLoadingButton;
        protected var _btnName:String;
        protected var _swfPlayer:SWFPlayer;
        protected var _swfName:String;
        protected var _numberBox:NumberBox;
        private var _isPlayEffect:Boolean;
        private var _disEventName:String;
        protected var _countDownTime:ActionBaseTimerBox;
        private var _sortId:int;
        protected var _state:int = -1;
        private var _lvCheckShow:Boolean;
        public static var sortObj:Object = initSortObj();
        public static const State_ToBeOpen:int = 1;
        public static const State_Opening:int = 2;
        public static const State_DayEnd:int = 3;
        public static const State_Close:int = -1;

        public function ActionBaseIcon(param1:String)
        {
            this._btnName = param1;
            this.layer = LayerManager.actionIconLayer;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.btn = UIFactory.gLoadingButton(this._btnName, 0, 0, 56, 54, this);
            this.configEventListener(MouseEvent.CLICK, this.clickHandler);
            if (this.limitLv() > 0)
            {
                LevelCheckUtil.addLevelUp(this.levelUpHd);
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this.btn.dispose(param1);
            this.btn = null;
            this._sortId = 0;
            if (this._swfPlayer)
            {
                this._swfPlayer.dispose(param1);
                this._swfPlayer = null;
            }
            this._isPlayEffect = false;
            this._disEventName = "";
            if (this._numberBox)
            {
                this._numberBox.dispose(param1);
                this._numberBox = null;
            }
            if (this._countDownTime)
            {
                this._countDownTime.dispose(param1);
                this._countDownTime = null;
            }
            this._state = State_Close;
            this._lvCheckShow = false;
            super.disposeImpl(param1);
            return;
        }// end function

        protected function limitLv() : int
        {
            return 0;
        }// end function

        protected function levelUpHd(param1:Object) : void
        {
            var _loc_2:* = this.limitLv();
            if (this._lvCheckShow && LevelCheckUtil.curLevel >= _loc_2)
            {
                super.show();
                this._lvCheckShow = false;
            }
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            var _loc_3:* = this.limitLv();
            if (_loc_3 > 0 && LevelCheckUtil.curLevel < _loc_3)
            {
                this._lvCheckShow = true;
            }
            else
            {
                this._lvCheckShow = false;
            }
            if (!this._lvCheckShow)
            {
                super.show(param1, param2);
            }
            return;
        }// end function

        protected function setIconTxt(param1:String = "") : void
        {
            if (param1)
            {
                if (this._numberBox == null)
                {
                    this._numberBox = UICompomentPool.getUICompoment(NumberBox);
                    this._numberBox.x = 27;
                    this._numberBox.y = 0;
                    this.addChild(this._numberBox);
                }
                this._numberBox.text = param1.toString();
            }
            else if (this._numberBox)
            {
                this._numberBox.dispose();
                this._numberBox = null;
            }
            return;
        }// end function

        public function playEffect(param1:String = "ActionIconEffect.swf") : void
        {
            if (!this._swfPlayer)
            {
                this._swfPlayer = UIFactory.getUICompoment(SWFPlayer);
                this._swfPlayer.timeRate = 3;
                this._swfPlayer.move(28, 27);
                this._swfPlayer.load(param1, ModelType.NormalSwf, null);
            }
            if (!this._isPlayEffect)
            {
                this.addChild(this._swfPlayer);
                this._isPlayEffect = true;
                this.dispatchEvent(new DataEvent(EventName.ActionIconPlayEffect));
            }
            return;
        }// end function

        public function stopEffect() : void
        {
            if (this._swfPlayer && this._swfPlayer.parent)
            {
                this.removeChild(this._swfPlayer);
            }
            if (this._isPlayEffect)
            {
                this._isPlayEffect = false;
                this.dispatchEvent(new DataEvent(EventName.ActionIconPlayEffect));
            }
            return;
        }// end function

        protected function clickHandler(event:MouseEvent) : void
        {
            if (this._disEventName != "" && this._disEventName != null)
            {
                Dispatcher.dispatchEvent(new DataEvent(this._disEventName));
            }
            return;
        }// end function

        public function fly() : void
        {
            LayerManager.actionIconLayer.addPopUpFly(this);
            return;
        }// end function

        public function get btnName() : String
        {
            return this._btnName;
        }// end function

        public function set btnName(param1:String) : void
        {
            this._btnName = param1;
            return;
        }// end function

        public function get isPlayEffect() : Boolean
        {
            return this._isPlayEffect;
        }// end function

        public function set isPlayEffect(param1:Boolean) : void
        {
            this._isPlayEffect = param1;
            return;
        }// end function

        public function get disEventName() : String
        {
            return this._disEventName;
        }// end function

        public function set disEventName(param1:String) : void
        {
            this._disEventName = param1;
            return;
        }// end function

        public function setLeftTimeAndState(param1:int, param2:int = 1, param3:String = "mm:ss", param4:Boolean = true) : void
        {
            this._state = param2;
            if (param1 > 0)
            {
                if (this._countDownTime == null)
                {
                    this._countDownTime = UICompomentPool.getUICompoment(ActionBaseTimerBox);
                    this._countDownTime.move(-3, 52);
                    this.addChild(this._countDownTime);
                }
                this._countDownTime.setParse(param3);
                this._countDownTime.numberTxtUrl = this.getNumberTxtUrl(this._state);
                this._countDownTime.leftTime = param1;
                this._countDownTime.timeUpdateCaller = this.timeUpdateCaller;
                this._countDownTime.timeOutCaller = this.timeOutCaller;
                if (param4)
                {
                    this._countDownTime.stateImageUrl = this.getStateImageUrlByState(this._state);
                }
                else
                {
                    this._countDownTime.stateImageUrl = this.getStateImageUrlByState(-1);
                }
            }
            else
            {
                this.removeTimer();
            }
            return;
        }// end function

        public function removeTimer() : void
        {
            if (this._countDownTime)
            {
                this._countDownTime.dispose();
                this._countDownTime = null;
            }
            return;
        }// end function

        protected function getNumberTxtUrl(param1:int) : String
        {
            var _loc_2:String = null;
            switch(param1)
            {
                case 0:
                case 1:
                {
                    _loc_2 = "ActiveTimerNum.png";
                    break;
                }
                case 2:
                case 3:
                {
                    _loc_2 = "ActiveTimerNumRed.png";
                    break;
                }
                default:
                {
                    break;
                }
            }
            return _loc_2;
        }// end function

        protected function getStateImageUrlByState(param1:int) : String
        {
            var _loc_2:String = null;
            switch(param1)
            {
                case -1:
                {
                    _loc_2 = "";
                    break;
                }
                case 0:
                {
                    _loc_2 = ImagesConst.ActiveTimer_Signup;
                    break;
                }
                case 1:
                {
                    _loc_2 = ImagesConst.ActiveTimer_Start;
                    break;
                }
                case 2:
                {
                    _loc_2 = ImagesConst.ActiveTimer_End;
                    break;
                }
                case 3:
                {
                    _loc_2 = ImagesConst.ActiveTimer_DayEnd;
                    break;
                }
                default:
                {
                    break;
                }
            }
            return _loc_2;
        }// end function

        protected function timeOutCaller() : void
        {
            return;
        }// end function

        protected function timeUpdateCaller() : void
        {
            return;
        }// end function

        public function get leftTime() : int
        {
            if (this._countDownTime)
            {
                return this._countDownTime.leftTime;
            }
            return 0;
        }// end function

        public function get currentTimeStr() : String
        {
            if (this._countDownTime)
            {
                return this._countDownTime.currentTimeStr;
            }
            return "00:00";
        }// end function

        public function get sortId() : int
        {
            this._sortId = int(sortObj[this._btnName]);
            return this._sortId;
        }// end function

        private static function initSortObj() : Object
        {
            sortObj = {};
            var _loc_1:int = 100;
            sortObj[ResFileConst.QuestionIcon] = 0;
            sortObj[ResFileConst.WorldBossIcon] = _loc_1 + 1;
            var _loc_2:int = 1000;
            sortObj[ResFileConst.Comsum200Icon] = _loc_2 + 1;
            sortObj[ResFileConst.RebateDayRechargeIcon] = _loc_2 + 1;
            sortObj[ResFileConst.YYZiZuanIcon] = _loc_2 + 1;
            sortObj[ResFileConst.VipIcon] = _loc_2 + 1;
            sortObj[ResFileConst.FirstRechargeDay500Icon] = _loc_2 + 1;
            sortObj[ResFileConst.FirstReChargeIcon] = _loc_2 + 1;
            sortObj[ResFileConst.RechargeDailyTotalIcon] = _loc_2 + 1;
            sortObj[ResFileConst.lotteryDrawIcon] = _loc_2 + 1;
            sortObj[ResFileConst.MonthInvestmentIcon] = _loc_2 + 1;
            sortObj[ResFileConst.investment] = _loc_2 + 1;
            sortObj[ResFileConst.ThanksGivingIcon] = _loc_2 + 1;
            return sortObj;
        }// end function

    }
}
